#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

typedef struct STU
{
	int iId;
	char caName[32];
	float fScore;
}STU;

void print(const STU *stu, int count)
{
	if (NULL == stu || count <= 0)
	{
		return;
	}
	int i = 0;
	for (; i<count; i++)
	{
		printf("id:%d, name:%s, score:%.1f\n", stu[i].iId
			   , stu[i].caName, stu[i].fScore);
	}
}

void bubble(STU *stu, int count)
{
	if (NULL == stu || count <= 0)
	{
		return;
	}
	int i = 0;
	int j = 0;
	STU tmp;
	for (; i<count-1; i++)
	{
		for (j=0; j<count-i-1; j++)
		{
			if (stu[j].fScore > stu[j+1].fScore)
			{
				tmp = stu[j];
				stu[j] = stu[j+1];
				stu[j+1] = tmp;		
			}
		}
	}
}

int main(void)
{
	STU stu[5] = {{1001, "jack", 89}
	              , {1002, "rose", 21}
	              , {1003, "tony", 39}
	              , {1004, "peter", 66}
	              , {1005, "jimy", 44}};

	print(stu, 5);
	printf("-----------------------\n");
	bubble(stu, 5);
	print(stu, 5);




	return 0;
}
